import aiohttp,asyncio


async def run():
    conn = aiohttp.TCPConnector(ssl=False)
    # 设置请求超时时间
    timeout = aiohttp.ClientTimeout(total=10)
    async with aiohttp.ClientSession(connector=conn, headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
        }, timeout=timeout) as client:
        async with client.get('http://www.anahd.co.jp') as resp:
            print(resp.status)
            if resp.status == 200 or str(resp.status).startswith("2") or str(resp.status).startswith(
                    "3"):
                # 获取相应数据的编码格式
                # charset = charset_normalizer.detect(resp.text())['encoding']
                print(await resp.text())
                print('success')
            else:
                raise Exception('error request,retesting')


try:
    task = asyncio.ensure_future(run())
    loop = asyncio.get_event_loop()
    loop.run_until_complete(task)
except Exception as e:
    print(e)

# from selenium import webdriver
#
# driver = webdriver.Chrome()
# driver.get('http://clublegend.com.au')
# print(driver.page_source)
